package graph.day05;

import java.util.*;

public class Kama_110 {

    static Set<String> set = new HashSet<>();
    static Map<String, Integer> map = new HashMap<>();

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String beginStr = sc.next();
        String endStr = sc.next();
        for (int i = 0; i < n; i++) set.add(sc.next());
        // key: str, value: path
        map.put(beginStr, 1);

        // abc(1) dbc(2) ebc(2) dec(3) efc(3) dfc(3) def(4)
        Queue<String> queue = new LinkedList<>();
        // 存入起点
        queue.offer(beginStr);
        while (!queue.isEmpty()) {
            String word = queue.poll();
            int path = map.get(word);
            for (int i = 0; i < word.length(); i++) {
                char[] arr = word.toCharArray();
                for (char c = 'a'; c <= 'z'; c++) {
                    arr[i] = c;
                    String word2 = new String(arr);
                    // 到达终点
                    if (word2.equals(endStr)) {
                        System.out.println(path + 1);
                        return;
                    }
                    // 下一节点
                    if (set.contains(word2) && !map.containsKey(word2)) {
                        map.put(word2, path + 1);
                        queue.offer(word2);
                    }
                }
            }
        }
        System.out.println(0);
    }
}
